home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / dvitobit.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  22KB  |  703 lines

  1. #if ( defined DJ || defined EMXOS2 )      /* a.r. */
  2. #define unix
  3. #endif
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <string.h>
  8. #include <assert.h>
  9. #include <math.h>
  10. #ifdef __TURBOC__
  11. extern unsigned _stklen=20000;
  12. #include <alloc.h>
  13. #else
  14. #define huge
  15. #endif
  16. #include "int32.h"
  17.  
  18. #define true (!false)
  19. #define false 0
  20. #include "bmp.h"
  21. #include "dvipath.h"
  22.  
  23. double d_xscale, d_yscale;
  24. int gdebug=false;
  25. int fittobit;   /* true if picture should be scaled up to fit bitmap, wp-tiff */
  26.  
  27. #define scx(v) ( ((v) * d_xscale + 1))
  28. #define scy(v) ( ((v) * d_yscale + 1))
  29. #define dbg if (gdebug)
  30.  
  31. char *bgidir();
  32. int path_bezier(int  x1, int  y1, int  x2, int  y2, int  x3, int  y3);
  33. int path_alloc(void);
  34. int path_move(int  x1, int  y1);
  35. int path_line(int  x1, int  y1);
  36. int path_closepath(void);
  37.  
  38. int dev_print(Bitmap *b);
  39. int dev_size(int *nxbits, int *nybits, double *devxcm, double *devycm);
  40. int dev_hpplus;
  41. int dev_hires,dev_vhires;
  42. int dev_noff;
  43. int dev_noclip;
  44. int dev_nosquash;
  45. int dev_wide;
  46. double devxcm,devycm;
  47. double uxcm,uycm;
  48.  
  49. Bitmap *bb;
  50. /*---------------------------------------------------------------------------*/
  51. /*      Local stuff */
  52. int flipit;
  53. FILE *outbit;
  54. FILE *inf;
  55. /*---------------------------------------------------------------------------*/
  56. main_usage()
  57. {
  58.         printf("Usage: dviprint [-depson | -dlj] [-old] [-hires] [-vhires] [-debug] [-output xx.prt]\n");
  59.         printf("    -depson   To produce output for epson printers \n");
  60.         printf("    -dwp      To add tiff image to wp .eps file \n");
  61.         printf("    -dec      Epson color ribbon printers \n");
  62.         printf("    -dlj      To produce output for HP LaserJet printers \n");
  63.         printf("    -dpj      To produce output for HP PaintJet printers \n");
  64.         printf("    -dsx      Sixel graphics, for DEC printers la100's ...\n");
  65.         printf("    -dvt      To print bitmap to screen (preview) \n");
  66.         printf("    -over     Overhead transparency mode for PaintJet\n");
  67.         printf("    -old      For old HP Laser Jet printers (no compression)\n");
  68.         printf("    -hires    Uses high resolution for that printer (slower)\n");
  69.         printf("    -vhires   Viritcal high resolution for sixel graphics\n");
  70.         printf("    -wide     If your printer has a wide carriage \n");
  71.         printf("    -noflip   Disable's auto flipping \n");
  72.         printf("    -flip     Forces flip  \n");
  73.         printf("    -nosquash Tries to print it full size\n");
  74.         printf("    -compress Force internal bitmap compression (slow) \n");
  75.         printf("    -noff     No form feed\n");
  76.         printf("    -debug    Prints debug messages\n");
  77.         printf("    -out x.x  Prints output to file instead of printer port\n");
  78.         printf("\n");
  79. }
  80. enum {D_EPSON=1,D_LJ,D_VT,D_PJ,D_WP,D_EC,D_SX};
  81. int dev_type,dev_noflip,dev_lowmem,dev_low,dev_over,dev_flip;
  82. int dev_nops=false;
  83. int bmp_compress;
  84. char outbitname[80];
  85. char gleroot[90];
  86. main(int argc, char **argv)
  87. {
  88.         int i;
  89.         char *ss;
  90.         strcpy(gleroot,argv[0]);
  91. #ifdef __TURBOC__
  92.         ss = strchr(gleroot,'\\');
  93.         if (ss==NULL) printf("Unable to locate files AGRV[0] wrong");
  94.         for (;strchr(ss+1,'\\')!=NULL;) ss = strchr(ss+1,'\\');
  95.         *(ss+1) = 0;
  96. #endif
  97.  
  98.         if (argc<=1) { main_usage(); exit(0);}
  99.  
  100.         inf = fopen("out.dvi","rb");
  101.         if (inf==NULL) {
  102.                 printf("Unable to open OUT.DVI for input, run DVIGLE first\n");
  103.                 gle_abort("");
  104.         }
  105.  
  106.         dev_hpplus = true;
  107.         for (i=1;i<argc; i++) {
  108. #ifdef __TURBOC__
  109.                 strlwr(argv[i]);
  110. #endif
  111.                 if (strncmp(argv[i],"/o",2)==0) dev_hpplus = false;
  112.                 else if (strncmp(argv[i],"/h",2)==0) dev_hires = true;
  113.                 else if (strncmp(argv[i],"-ol",3)==0) dev_hpplus = false;
  114.                 else if (strncmp(argv[i],"-ov",3)==0) dev_over = true;
  115.                 else if (strncmp(argv[i],"-me",3)==0) dev_lowmem = false;
  116.                 else if (strncmp(argv[i],"-co",3)==0) bmp_compress = true;
  117.                 else if (strncmp(argv[i],"-lo",3)==0) dev_low = true;
  118.                 else if (strncmp(argv[i],"-h",2)==0) dev_hires = true;
  119.                 else if (strncmp(argv[i],"-vh",3)==0) dev_vhires = true;
  120.                 else if (strncmp(argv[i],"-nops",5)==0) dev_nops = true;
  121.                 else if (strncmp(argv[i],"-nosq",5)==0) dev_nosquash = true;
  122.                 else if (strncmp(argv[i],"-wi",3)==0) dev_wide = true;
  123.                 else if (strncmp(argv[i],"-noff",5)==0) dev_noff = true;
  124.                 else if (strncmp(argv[i],"-nocl",5)==0) dev_noclip = true;
  125.                 else if (strncmp(argv[i],"-n",2)==0) dev_noflip = true;
  126.                 else if (strncmp(argv[i],"-fl",3)==0) dev_flip = true;
  127.                 else if (strncmp(argv[i],"-deb",4)==0) gdebug = true;
  128.                 else if (strncmp(argv[i],"-dwp",4)==0) dev_type = D_WP;
  129.                 else if (strncmp(argv[i],"-dec",4)==0) dev_type = D_EC;
  130.                 else if (strncmp(argv[i],"-dsx",4)==0) dev_type = D_SX;
  131.                 else if (strncmp(argv[i],"-dep",4)==0) dev_type = D_EPSON;
  132.                 else if (strncmp(argv[i],"-dl",3)==0) dev_type = D_LJ;
  133.                 else if (strncmp(argv[i],"-dv",3)==0) dev_type = D_VT;
  134.                 else if (strncmp(argv[i],"-dp",3)==0) dev_type = D_PJ;
  135.                 else if (strncmp(argv[i],"-o",2)==0) {
  136.                         strcpy(outbitname,argv[++i]);
  137.                 }
  138.                 else {
  139.                         printf("Unrecognised qualifier, {%s} \n",argv[i]);
  140.                         main_usage();
  141.                         exit(0);
  142.                 }
  143.         }
  144.         if (dev_type==0) { main_usage(); exit(0);}
  145. #if ( defined DJ )   /* a.r. */
  146.         if (dev_type == D_VT)
  147.                 strcpy(outbitname, "nul");
  148.         if (strlen(outbitname) == 0)
  149.                 {
  150.                   fprintf( stderr, "\nError:\n");
  151.                   fprintf( stderr, "You must specify a *file*-name for output with this version of GLE!\n");
  152.                   fprintf( stderr, "Example:\n");
  153.                   fprintf( stderr, "gle_dvip -dlj -hires -out laserjet.bin\n");
  154.                   fprintf( stderr, "Now your're able to print by copying the output to your printer, e.g.:\n");
  155.                   fprintf( stderr, "copy /b laserjet.bin lpt1\n");
  156.                   exit(1);
  157.                 }
  158. #endif
  159.         if (dev_type==D_WP) {
  160.           if (strcmp(outbitname,"out.dvi")==0) {
  161.                 printf("Must specify name of .eps file to add tiff too.\n");
  162.                 exit(0);
  163.           }
  164.           if (strstr(outbitname,".")!=0) {
  165.                 * strchr(outbitname,'.') = 0;
  166.           }
  167.           strcat(outbitname,".epf");
  168.         }
  169.         if (strstr(outbitname,".gle")!=0) {
  170.                 printf("Will not erase a .gle file\n");
  171.                 exit(0);
  172.         }
  173.         open_outbit(outbitname);
  174.         draw_file();
  175.         close_output();
  176. #ifdef VMS
  177.         return 1;
  178. #else
  179.         return 0;
  180. #endif
  181. }
  182. /*---------------------------------------------------------------------------*/
  183. open_outbit(char *outbitname)
  184. {
  185. #if __TURBOC__
  186.         if (strlen(outbitname)!=0) {
  187.           printf("Writing output to file {%s} \n",outbitname);
  188.           outbit = fopen(outbitname,"wb");
  189.           if (outbit==NULL) {
  190.                 printf("Could not open that FILE for output {%s} \n",outbitname);
  191.                 perror("");
  192.                 exit(1);
  193.           }
  194.         } else  printf("Printing to LPT1 \n");
  195. #else
  196.  
  197.                 /* Special binary open for VMS */
  198. /*  strcpy(outbitname,"out.prt"); */
  199.         printf("Writing output to file {%s} \n",outbitname);
  200. #ifdef unix
  201.         if ((outbit = fopen(outbitname,"wb")) == NULL)
  202. #else
  203.         if ((outbit = fopen (outbitname,"wb","rfm=fix","bls=512","mrs=512")) == NULL)
  204. #endif
  205.         {   printf ("Can't open output bitmap file.\n");
  206.                         abort();
  207.                 }
  208. #endif
  209. }
  210. /*---------------------------------------------------------------------------*/
  211. /*   Path variables for bitmap */
  212. int *path;
  213. int npath;
  214. int npath_alloc;
  215.  
  216. int file_end = false;
  217. float getf(void);
  218. int getfxy(int *x, int *y);
  219. getfxy(int *x, int  *y)
  220. {
  221.         float u,xx,yy;
  222.         xx = getf();
  223.         yy = getf();
  224.         if (flipit) {
  225.                 u = yy;
  226.                 yy = uxcm - xx;
  227.                 xx = u;
  228.         }
  229.         /*printf("fxy %g %g \n",xx,yy); */
  230.         *x = (int) .5+scx(xx);
  231.         *y = (int) .5+scy(yy);
  232. }
  233. float getf(void)
  234. {
  235.         static float x;
  236.         fread(&x,sizeof(x),1,inf);
  237.         if (feof(inf)) file_end = true;
  238.         return x;
  239. }
  240. int32 getl(void)
  241. {
  242.         static int32 x;
  243.         fread(&x,sizeof(x),1,inf);
  244.         if (feof(inf)) file_end = true;
  245.         return x;
  246. }
  247.  
  248.  
  249. float cur_lwidth,cur_color,cur_fill,cur_dashlen;
  250. int32 cur_lstyle;
  251.  
  252. draw_file(void)
  253. {
  254.         int x2,y2,x3,y3,sx,sy;
  255.         int x,y,cx,cy;
  256.         int g=0;
  257.         float fx,fy;
  258.         int i,dot;
  259.  
  260.         for (;!file_end;) {
  261.           i = getl();
  262.           if (file_end) break;
  263.           switch (i) {
  264.                 case p_size:
  265.                         dbg printf("#size \n");
  266.                         fx = getf(); fy = getf();
  267.                         d_open(fx,fy);
  268.                         dbg printf(":");
  269.                 case p_newpath:
  270.                         dbg printf("#newpath \n");
  271.                         npath = 0;
  272.                         break;
  273.                 case p_move:
  274.                         getfxy(&x,&y);
  275.                         cx = x; cy = y;
  276.                         dbg printf("#move (%d) %d %d  \n",npath,x,y);
  277.                         path_move(x,y);
  278.                         sx = cx; sy = cy;
  279.                         break;
  280.                 case p_line:
  281.                         dbg {g++; if (g>200) {printf(":"); g=0;}}
  282.                         getfxy(&x,&y);
  283.                         cx = x; cy = y;
  284.                         dbg printf("#line (%d) %d %d  \n",npath,x,y);
  285.                         path_line(x,y);
  286.                         break;
  287.                 case p_closepath:
  288.                         dbg printf("#closepath %d %d \n",sx,sy);
  289.                         path_closepath();
  290.                         cx = sx; cy = sy;
  291.                         break;
  292.                 case p_dline:
  293.                         dbg {g++; if (g>200) {printf(":"); g=0;}}
  294.                         getfxy(&x,&y);
  295.                         bmp_line(bb,cx,cy,x,y);
  296.                         npath = 0;
  297.                         dbg printf("#(nopath)line %d %d %d %d  \n",cx,cy,x,y);
  298.                         cx = x; cy = y;
  299.                         break;
  300.                 case p_bezier:
  301.                         getfxy(&x,&y);
  302.                         getfxy(&x2,&y2);
  303.                         getfxy(&x3,&y3);
  304.                         path_bezier(x,y,x2,y2,x3,y3);
  305.                         dbg printf("#bezier (%d)\n",npath);
  306.                         cx = x3; cy = y3;
  307.                         break;
  308.                 case p_stroke:
  309.                         dbg printf("#stroke \n");
  310.                         path_stroke();
  311.                         break;
  312.                 case p_fill:
  313.                         dbg printf("#fill \n");
  314.                         path_fill();
  315.                         break;
  316.                 case p_lwidth:
  317.                         dbg printf("#lwidth \n");
  318.                         cur_lwidth = getf();
  319.                         bmp_lwidth(bb,(int) scx(cur_lwidth));
  320.                         break;
  321.                 case p_dashlen:
  322.                         dbg printf("#dashlen \n");
  323.                         cur_dashlen = getf();
  324.                                                 dot=(int)(0.5+d_yscale*cur_dashlen);
  325.                                                 dot = dot > 0 ? dot : 1;
  326.                         bmp_lstyle(bb,cur_lstyle,dot);
  327.                         break;
  328.                 case p_lstyle:
  329.                         dbg printf("#lstyle \n");
  330.                         cur_lstyle = getl();
  331.                                                 dot=(int)(0.5+d_yscale*cur_dashlen);
  332.                                                 dot = dot > 0 ? dot : 1;
  333.                         bmp_lstyle(bb,cur_lstyle,dot);
  334.                         break;
  335.                 case p_setcolor:
  336.                         x = getl(); x2 = getl(); x3 = getl(); y = getl();
  337.                         dbg printf("#setcolor %d %d %d f=%d \n",x,x2,x3,y);
  338.                         bmp_setcolor(bb,x,x2,x3,y); /* r,g,b,f */
  339.                         break;
  340.                 case p_clip:
  341.                         dbg printf("#clipcurpath \n");
  342.                         path_clip();
  343.                         break;
  344.                 case p_saveclip:
  345.                         dbg printf("#save clip \n");
  346.                         bmp_saveclip(bb);
  347.                         break;
  348.                 case p_restoreclip:
  349.                         dbg printf("#restore clip \n");
  350.                         bmp_restoreclip(bb);
  351.                         break;
  352.                 case p_null:
  353.                         dbg printf("Null \n");
  354.                         break;
  355.                 default:
  356.                         printf("Error in PATH codes in .DVI file %d\n",i);
  357.                         break;
  358.           }
  359.         }
  360.         d_close();
  361. }
  362. gle_abort(char *s)
  363. {
  364.         printf("%s",s);
  365.         exit(1);
  366. }
  367. path_send()
  368. {
  369.         int sx=0,sy=0,cx=0,cy=0,x1,y1,x2,y2,x3,y3;
  370.         int closed=true;
  371.         int i,j,p1,p2;
  372.  
  373.         bmp_newpath(bb);
  374.         for (i=0;i<npath;i++) {
  375.           switch(path[i]) {
  376.                 case p_move:
  377.                 sx = path[++i];
  378.                 sy = path[++i];
  379.                 bmp_pmove(bb,sx,sy);
  380.                 cx = sx; cy = sy;
  381.                 break;
  382.                 case p_line:
  383.                 x1 = path[++i];
  384.                 y1 = path[++i];
  385.                 dbg printf("pline %d %d \n",x1,y1);
  386.                 bmp_pline(bb,x1,y1);
  387.                 cx = x1; cy = y1;
  388.                 break;
  389.                 case p_bezier:
  390.                 x1 = path[++i];  y1 = path[++i];
  391.                 x2 = path[++i];  y2 = path[++i];
  392.                 x3 = path[++i];  y3 = path[++i];
  393.                 dbg printf("pbezier %d %d   %d %d   %d %d\n",x1,y1,x2,y2,x3,y3);
  394.                 bmp_pbezier(bb,cx,cy,x1,y1,x2,y2,x3,y3);
  395.                 cx = x3; cy = y3;
  396.                 break;
  397.                 case p_closepath:
  398.                 dbg if (cx!=sx || cy!=sy) printf("pclosepath %d %d \n",sx,sy);
  399.                 if (cx!=sx || cy!=sy) bmp_pline(bb,sx,sy);
  400.                 cx = sx; cy = sy;
  401.                 break;
  402.                 default:
  403.                 printf("Error in path_fill code path[%d] %d \n",i,path[i]);
  404.           }
  405.         }
  406. }
  407. path_fill(void)
  408. {
  409.         path_send();
  410.         bmp_fill(bb);
  411. }
  412. path_clip(void)
  413. {
  414.         path_send();
  415.         bmp_clip(bb);
  416. }
  417. path_stroke(void)
  418. {
  419.         int sx=0,sy=0,cx=0,cy=0,x1,y1,x2,y2,x3,y3;
  420.         int closed=true;
  421.         int i,j,p1,p2;
  422.  
  423.         bmp_newpath(bb);
  424.         for (i=0;i<npath;i++) {
  425.           switch(path[i]) {
  426.                 case p_move:
  427.                 sx = path[++i];
  428.                 sy = path[++i];
  429.                 cx = sx; cy = sy;
  430.                 break;
  431.                 case p_line:
  432.                 x1 = path[++i];
  433.                 y1 = path[++i];
  434.                 bmp_line(bb,cx,cy,x1,y1);
  435.                 cx = x1; cy = y1;
  436.                 break;
  437.                 case p_bezier:
  438.                 x1 = path[++i];  y1 = path[++i];
  439.                 x2 = path[++i];  y2 = path[++i];
  440.                 x3 = path[++i];  y3 = path[++i];
  441.                 bmp_bezier(bb,cx,cy,x1,y1,x2,y2,x3,y3);
  442.                 cx = x3; cy = y3;
  443.                 break;
  444.                 case p_closepath:
  445.                 if (cx!=sx || cy!=sy) bmp_line(bb,cx,cy,sx,sy);
  446.                 cx = sx; cy = sy;
  447.                 break;
  448.                 default:
  449.                 printf("Error in path_fill code path[%d] %d \n",i,path[i]);
  450.           }
  451.         }
  452. }
  453. path_move(int  x,int y)
  454. {
  455.         path_alloc();
  456.         path[npath++] = p_move;
  457.         path[npath++] = x;
  458.         path[npath++] = y;
  459. }
  460. path_line(int x,int y)
  461. {
  462.         path_alloc();
  463.         path[npath++] = p_line;
  464.         path[npath++] = x;
  465.         path[npath++] = y;
  466. }
  467. path_bezier(int x1, int y1, int x2, int y2,int x3, int y3)
  468. {
  469.         path_alloc();
  470.         path[npath++] = p_bezier;
  471.         path[npath++] = x1; path[npath++] = y1;
  472.         path[npath++] = x2; path[npath++] = y2;
  473.         path[npath++] = x3; path[npath++] = y3;
  474. }
  475. path_closepath()
  476. {
  477.         path_alloc();
  478.         path[npath++] = p_closepath;
  479. }
  480. path_alloc(void)
  481. {
  482.         static int npa;
  483.         int *a;
  484.  
  485.         if (npath < (npath_alloc-10)) return;
  486.         npath_alloc = 20 + 2 * npath;
  487.         if (npath_alloc<300) npath_alloc = 300;
  488.         dbg  printf("=== Allocate %d %d \n",npath_alloc,npath);
  489.         a = (int *) calloc(1,npath_alloc*sizeof(int));
  490.         if (a==NULL) {
  491.                 gle_abort("Unable to allocate memory for path \n");
  492.         }
  493.         if (path != NULL) {
  494.                 dbg printf("path reallocate, copy \n");
  495.                 memcpy(a,path,(npa)*sizeof(int));
  496.                 free(path);
  497.         }
  498.         npa = npath_alloc;
  499.         path = a;
  500. }
  501. path_free(void)
  502. {
  503.         if (path==NULL) return;
  504.         free(path);
  505.         path = NULL;
  506.         npath = 0;
  507.         npath_alloc = 0;
  508. }
  509.  
  510. d_open(double width, double height)
  511. {
  512.         double f,f1,f2,fx,fy;
  513.         double d_scale;
  514.         int nxbits,nybits;
  515.  
  516.         {devxcm = width; devycm = height;}
  517.         if (!dev_noflip &&  width>height &&!dev_wide) {devxcm = height; devycm = width;}
  518.         switch (dev_type) {
  519.           case D_EPSON:
  520.                 dev_size_ep(&nxbits, &nybits, &devxcm, &devycm);
  521.                 break;
  522.           case D_EC:
  523.                 dev_size_ec(&nxbits, &nybits, &devxcm, &devycm);
  524.                 break;
  525.           case D_WP:
  526.                 dev_size_wp(&nxbits, &nybits, &devxcm, &devycm);
  527.                 break;
  528.           case D_SX:
  529.                 dev_size_sx(&nxbits, &nybits, &devxcm, &devycm);
  530.                 break;
  531.           case D_LJ:
  532.                 dev_size_lj(&nxbits, &nybits, &devxcm, &devycm);
  533.                 break;
  534.           case D_VT:
  535.                 dev_size_vt(&nxbits, &nybits, &devxcm, &devycm);
  536.                 break;
  537.           case D_PJ:
  538.                 dev_size_pj(&nxbits, &nybits, &devxcm, &devycm);
  539.                 break;
  540.         }
  541.         uxcm = width; uycm = height;
  542.  
  543.         d_scale = devxcm / width;
  544.         f = devycm / height;
  545.         if (f<d_scale) d_scale = f;
  546.  
  547.         if (fittobit) {
  548.                 fx = devxcm / width;
  549.                 d_scale = 1;
  550.                 fy = devycm / height;
  551.         }
  552.         if (d_scale<.98) {
  553.                 if ( dev_flip
  554.                 || (dev_wide && !dev_noflip && height>width )
  555.                 ||   ( !dev_wide && width>height && !dev_noflip)
  556.                 ) {
  557.                         d_scale = devycm/width;
  558.                         f = devxcm/height;
  559.                         if (f<d_scale) d_scale = f;
  560.                         flipit = true;
  561.                         printf("Flipping graph to fit on page better \n");
  562.                 }
  563.         }
  564.  
  565.         /* Get correct size of drawing */
  566.         if (d_scale > 1.001) d_scale = 1;
  567.         else {
  568.                 if (d_scale < .99) printf("Squashing onto page by factor %g \n",d_scale);
  569.         }
  570.  
  571.         d_xscale = d_scale * (nxbits-2) / devxcm; /* Device Scale X, Device Scale y */
  572.         d_yscale = d_scale * (nybits-2) / devycm;
  573.         if (fittobit) {
  574.                 d_xscale = fx * (nxbits-2) / devxcm;
  575.                 d_yscale = fy * (nybits-2) / devycm;
  576.         }
  577.         bb = bmp_open(nxbits,nybits,1,bmp_compress);
  578.         if (bb==NULL) gle_abort("Unable to create bitmap\n");
  579. }
  580. /*---------------------------------------------------------------------------*/
  581. d_close()
  582. {
  583.         path_free();
  584.         printf("Bitmap image created.\n");
  585.         switch (dev_type) {
  586.           case D_EPSON:
  587.                 dev_print_ep(bb);
  588.                 break;
  589.           case D_EC:
  590.                 dev_print_ec(bb);
  591.                 break;
  592.           case D_WP:
  593.                 dev_print_wp(bb);
  594.                 break;
  595.           case D_SX:
  596.                 dev_print_sx(bb);
  597.                 break;
  598.           case D_LJ:
  599.                 dev_print_lj(bb);
  600.                 break;
  601.           case D_PJ:
  602.                 dev_print_pj(bb);
  603.                 break;
  604.           case D_VT:
  605.                 dev_print_vt(bb);
  606.                 break;
  607.         }
  608.         bmp_close(bb);
  609. }
  610.  
  611. #ifdef __TURBOC__
  612. #include <dos.h>
  613. char put_out(char c);
  614. int status(void);
  615. status(void)
  616. {
  617.         union REGS reg;
  618.  
  619.         reg.h.ah = 2;
  620.         reg.x.dx = 0;
  621.         int86(0x17, ®, ®);
  622.         return (reg.h.ah & 0x80);
  623. }
  624. char put_out(char c)
  625. {
  626.         union REGS reg;
  627.         int w=0;
  628.         static int ft=0;
  629.  
  630.         if (outbit!=NULL) {
  631.                 fputc(c,outbit);
  632.                 return;
  633.         }
  634.         while (!status()) {
  635.                 w++;
  636.                 if (w>10000) if (ft==0) {printf("Printer Busy\n"); w=0; ft=1;}
  637.                 if (w>10000) {printf(".");  w=0;}
  638.         }
  639.         /* if (ft==1) printf("\n"); */
  640.         reg.h.ah = 0;
  641.         reg.h.al = c;
  642.         reg.x.dx = 0;
  643.         int86(0x17,®,®);
  644.         return (reg.h.ah);
  645. }
  646. close_output()
  647. {
  648.         if (outbit!=NULL) fclose(outbit);
  649. }
  650.  
  651. #else
  652.  
  653. #include <stdio.h>
  654. #ifdef VAXC
  655. #include <file.h>
  656. #endif
  657. char zzbuff[512];
  658. int nzz=0;
  659. put_out(char c)
  660. {
  661.         zzbuff[nzz++] = c;
  662.         if (nzz==512) {
  663.                 fwrite(zzbuff,nzz,1,outbit);
  664.                 nzz = 0;
  665.         }
  666. }
  667. close_output()
  668. {
  669.         if (nzz > 0)  { /* for vax, must send whole blocks */
  670.                 memset(zzbuff+nzz,0,512-nzz);
  671.                 fwrite(zzbuff,512,1,outbit);
  672.         }
  673.         fclose(outbit);
  674. }
  675.  
  676. #endif
  677. printmem(char *s, int n)
  678. {
  679.         for (;n>0;n--) put_out(*s++);
  680. }
  681.  
  682. char *bgidir()
  683. {
  684. #ifdef __TURBOC__
  685.         char *s;
  686.         static char xx[80];
  687.         s = getenv("GLE_BGI");
  688.         if (s==NULL) {
  689.                 strcpy(xx,gleroot);
  690.                 strcat(xx,"exe\\");
  691.                 s = xx;
  692.         }
  693.         return s;
  694. #endif
  695. #if ( defined DJ || defined EMXOS2 )   /* a.r. absolutely not necessary, but... */
  696.         return getenv("GLE32FONT");
  697. #elif __linux__
  698.         return getenv("GRXFONT");
  699. #endif
  700. }
  701.  
  702.  
  703.